<template>
    <div class="message-center-box">
        <div class="l-panel">
            <div class="center-box">
                <template v-if="newList.length != 0">
                    <div class="center-list" v-for="(item, index) in newList" :key="index">
                        <div class="list-top-box">
                            <p>
                                <span>{{item.noticeTitle}}</span>
                                丨 {{item.createTime}}
                            </p>
                            <div v-if="item.noticeType == '2'">
                                <el-button type="text" v-if="item.state == '2' && $authInfo.getAuthType() == 'D' && ($global.platform('lj') || (!$global.platform('lj') && item.paymentMethod != '2')) && item.userType != 'YD'" @click="edit(item)">重新编辑</el-button>
                                <el-button type="text" style="color: #006DB8;" @click="check(item.noticeJoin)">查看处方</el-button>
                            </div>
                        </div>
                        <p>{{item.noticeContent}}</p>
                    </div>
                </template>
                <div class="empty" v-else>
                    <empty></empty>
                </div>
            </div>
            <div>
                <div class="pagination-box">
                    <el-pagination background layout="prev, pager, next" @current-change="currentChange" :total="total">
                    </el-pagination>
                </div>
            </div>
        </div>

        <pdf-dialog ref="pdfDialog"></pdf-dialog>

        <!-- 中西药弹框 start -->
        <drug-dialog ref="drugDialog" @closed="closeDialog('westernMedicineDialog')"></drug-dialog>
        <!-- 中西药弹框 end -->
    </div>
</template>

<script>
    import empty from '../../../components/nodata/index'
    import pdfDialog from '@/components/chatroom/view-pdf';
    import DrugDialog from '@/components/chatroom/drug-dialog';
    export default {
        components: {
            empty,
            pdfDialog,
            'drug-dialog': DrugDialog
        },
        data() {
            return {
                newList: [],
                current: 1,
                total: 0,
                perscriptionId: '',
                viewPerscriptionVisible: false,
                drugOrderId: null, //处方订单编号
                drugOrderMsg: {}, //处方订单信息
                drugType: '', //中西药类型
                westernMedicineDialog: false, //西药弹框
            }
        },
        mounted() {
            this.getNewsList();
        },
        methods: {
            getNewsList() {
                let params = {
                    webToken: this.$authInfo.webToken(),
                    current: this.current,
                    size: 10
                }
                this.$ajax.getNewsList(params).then(res => {
                    let { code, data } = res;
                    code === 1 ? this.newList = data.list : ''
                    this.total = data.total
                }).catch(err => {
                    this.loading = false;
                    this.$message({
                        message: err.msg,
                        type: "error",
                    });
                });
            },
            currentChange(e) {
                this.current = e;
                this.getNewsList();
            },
            // 查看消息
            check(val) {
                if (val && val != 'null') {
                    let params = {
                        id: val,
                        resource: 4
                    };
                    this.$refs.pdfDialog && this.$refs.pdfDialog.onOpen(params);
                } else {
                    this.$message({
                        message: '暂无处方信息',
                        type: 'error',
                    })
                }
            },
            // 重新编辑
            edit(val) {
                this.drugOrderId = val.noticeJoin

                let data = {
                    drugId: Number(val.noticeJoin),
                }
                this.$refs.drugDialog.onOpen({
                    data,
                    isEdit: true,
                    paymentMethod: val.paymentMethod
                })
            },
            closeDialog(dialogName) { //关闭弹框
                if (dialogName == 'westernMedicineDialog') { //西药弹框
                    this.westernMedicineDialog = false;
                    this.getNewsList();
                }
            },
        }
    }
</script>

<style lang='scss'>
    .message-center-box {
        .l-panel {
            width: 100%;
            padding: 30px;
            overflow: scroll;
        }

        .center-box {
            height: 540px;
            overflow-y: auto;
            margin-bottom: 20px;
        }
    }

    .center-list {
        padding-bottom: 20px;
        border-bottom: 1px solid #dfdfdf;
        font-size: 14px;
        color: #757575;

        >p {
            color: #3c3c3c;
        }

        .list-top-box {
            display: flex;
            align-items: center;
            justify-content: space-between;

            >p {
                span {
                    font-size: 16px;
                    color: #3c3c3c;
                }
            }
        }
    }

    .empty {
        margin-top: 100px;
    }

    .pagination-box {
        text-align: right;
    }
</style>